package com.xcmg.employee.controller;


import com.xcmg.employee.entity.Staff;
import com.xcmg.employee.service.StaffServiceImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/employee")
public class EmployeeController {

    @Resource
    StaffServiceImp staffServiceImp;

    //{}占位符，@PathVariable("id")将占位符中的参数带入到方法的处理中
    @RequestMapping("/getStaff/{id}")
    public Staff getStaff(@PathVariable("id") int id)throws InterruptedException{

        Staff sa=staffServiceImp.findStaffById(id);
        //int a=1/0;
        return sa;
    }

    @RequestMapping("/addStaff")
    public int addStaff(){

        Staff staff=new Staff();
        staff.setName("zhang");
        staff.setAge("10");
        staff.setTel("123456");
        staff.setDepartName("zhikongsuo");
        int sa=staffServiceImp.insertStaff(staff);
        //返回受影响行数
        return sa;
    }

    @RequestMapping("/deleteStaff/{id}")
    public void deleteStaffById(@PathVariable("id") int id){
         staffServiceImp.deleteStaffById(id);

    }

    @RequestMapping("/update")
    public void updateStaffById(@RequestBody Staff staff){

        staffServiceImp.updateStaff(staff);
    }

    @RequestMapping("/testSentinel")
    public String testSentinel(){

        //int a=1/0;
        return "这是测试employee！！！！";
    }


}
